package com.ukao.steward.ui.menuLeft.personalCenter;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.MvpFragment;
import com.ukao.steward.bean.PersonalCenterBean;
import com.ukao.steward.consts.SaveParams;
import com.ukao.steward.pesenter.valetRunners.PersonalCenterPesenter;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.util.ImageUtils;
import com.ukao.steward.view.valetRunners.PersonalCenterView;
import com.ukao.steward.widget.ShapedImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 个人中心
 */
public class PersonalCenterFragment extends MvpFragment<PersonalCenterPesenter> implements PersonalCenterView {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.back_btn)
    ImageView backBtn;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.title_layout)
    RelativeLayout titleLayout;
    @BindView(R.id.imgPath)
    ShapedImageView imgPath;
    @BindView(R.id.product_name)
    TextView name;
    @BindView(R.id.phone)
    TextView phone;
    @BindView(R.id.take)
    TextView take;
    @BindView(R.id.take_layout)
    RelativeLayout takeLayout;
    @BindView(R.id.send)
    TextView send;
    @BindView(R.id.send_layout)
    RelativeLayout sendLayout;
    Unbinder unbinder;


    private String mParam1;
    private String mParam2;


    public static PersonalCenterFragment newInstance(String param1, String param2) {
        PersonalCenterFragment fragment = new PersonalCenterFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    protected PersonalCenterPesenter createPresenter() {
        return new PersonalCenterPesenter(this);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_personal_center, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    @Override
    protected void initView() {
        title.setText("个人中心");
        titleLayout.setBackgroundColor(getColors(R.color.colorPrimary));
        setStatusBarTintColor(R.color.normal_blue);
        boolean islogistics = SaveParams.getislogistics();
        if (islogistics) {
            takeLayout.setVisibility(View.GONE);
            sendLayout.setVisibility(View.GONE);

        }
    }

    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
        mvpPresenter.workerdetail();
    }

    @Override
    public void useInfoSucceed(PersonalCenterBean mInfoBean) {
        name.setText(CheckUtils.isEmptyString(mInfoBean.getName()));
        phone.setText(CheckUtils.isEmptyString(mInfoBean.getPhone()));
        ImageUtils.loadImage(_mActivity, SaveParams.getHeadimgPath(), imgPath, R.drawable.nav_header_header);
        take.setText(CheckUtils.isEmptyString(mInfoBean.getTake()) + CheckUtils.isEmptyString(mInfoBean.getTakeUnit()));
        send.setText(CheckUtils.isEmptyString(mInfoBean.getSend()) + CheckUtils.isEmptyString(mInfoBean.getSendUnit()));

    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.back_btn)
    public void onViewClicked() {
        finish();
    }
}
